<?php

// | Author: 阳顶天 <yangjie@wttai.com>
// +----------------------------------------------------------------------
namespace Card\Controller;


/**
 * API控制器
 * @author  阳顶天 <yangjie@wttai.com>
 */
class MediaController extends CardController {

   public function mediaAd(){

        if($this->_method != 'post'){
            $this->ajaxReturn(errorReturn('请用POST访问！'));
        }
        $tag = I('post.tag',0);
        $tag_id = I('post.tag_id',0);
        if ($tag == 1){
            //获取素材标签
            $category_list = M('category_items')->where(['status'=>1])->select();
        }
        $result['category_list'] = $category_list;
        $ad = M('category_items')->alias('a')->where(['a.id'=>$tag_id,'a.status'=>1])->join('LEFT JOIN kan_picture b on b.id = a.image')->field(['a.id','title','path'])->find();
        if (empty($ad)){
            $this->ajaxReturn(errorReturn('无数据'));
        }else{
            $ad['url'] = C(CARD_DOMAIN) . U('home/index',array('category'=>$tag_id));
        }
        $result['ad'] = $ad; 
        $this->ajaxReturn(successReturn($result));

   }
}
